//
//  HCVisitorTableViewController.swift
//  Hweibome
//
//  Created by 何川 on 15/12/6.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit

class HCVisitorTableViewController: UITableViewController {

    
    var userLogin = HCUserAccountViewModel.sharedAccount.accessToken != nil
    
    var visitorView:HCVisitorView?
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    private func setupVisitorView()
    {
        visitorView = HCVisitorView()
        //这里是把创建出来的访客视图赋值给view
        //不能给view直接创建访客视图实例，需要通过visitorView转一下，如果不转，那么就会出现2个实例，到至后面出现问题！
        //所以此处不只是简单的转一下，还有让其为一个对象
        view = visitorView
    
        
        
        visitorView?.registerButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        
        
    }
    @objc private func login(){
        printLog("调用了其它-HCVisitorView-控制器的空间，实现了方法")
        let oauthVC = HCOAuthViewController() 
        presentViewController(HCNavigationController(rootViewController:oauthVC), animated: true, completion: nil)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



}
